import request from '@/utils/request'

export function getSysInfo() {
  return request({
    url: '/getSysInfo',
    method: 'get'
  })
}

export function setSysInfo(data) {
  return request({
    url: '/setSysInfo',
    method: 'post',
    data
  })
}

export function getSysCfg() {
  return request({
    url: '/getSysCfg',
    method: 'get'
  })
}

export function setSysCfg(data) {
  return request({
    url: '/setSysCfg',
    method: 'post',
    data
  })
}

export function applyAndReboot(data) {
  return request({
    url: '/applyAndReboot',
    method: 'post',
    data
  })
}

export function getPortStatistics() {
  return request({
    url: '/getPortStatistics',
    method: 'get'
  })
}

export function clearPortStatistics() {
  return request({
    url: '/clearPortStatistics',
    method: 'post'
  })
}

export function upload(file) {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

export function upgradeSoftware(data) {
  return request({
    url: '/upgradeSoftware',
    method: 'post',
    data
  })
}

export function getLogLevel() {
  return request({
    url: '/getLogLevel',
    method: 'get'
  })
}

export function setLogLevel(data) {
  return request({
    url: '/setLogLevel',
    method: 'post',
    data
  })
}

export function exportLog() {
  return request({
    url: '/exportLog',
    method: 'get'
  })
}

export function deleteLog() {
  return request({
    url: '/deleteLog',
    method: 'get'
  })
}

// Function that accepts a custom baseURL
function customRequest(config) {
  return request({
    ...config,
    baseURL: config.baseURL || process.env.VUE_APP_BASE_API // Default to the base API if not passed
  })
}

export function getLogFile() {
  return customRequest({
    baseURL: '/',
    url: '/hdlc_log.txt', // Custom URL for the request
    method: 'get',
    responseType: 'blob'

  })
}

// export function getLogFile() {
//   return customRequest({
//     baseURL: 'http://127.0.0.1:5501',
//     url: '/message.txt', // Custom URL for the request
//     method: 'get',
//     responseType: 'blob'
//   })
// }
